# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Mayor.create(:name => 'Daley', :city => cities.first)

#clearing the tables
Group.destroy_all
User.destroy_all
Friendship.destroy_all
Popsicle.destroy_all
ReceiveMessage.destroy_all
Privacy.destroy_all

#creating new entities
User.create([{:name => 'Adrian', :description => 'Programmer at Waikato Uni', :type => 'User', :password => "password", :email => "amshawnz@visige.co.nz"},
			 {:name => 'Bob', :description => 'Friend of Adrian', :type => 'User', :password => "password", :email => "bob@visige.co.nz"},
			 {:name => 'Bill', :description => 'Another friend of Adrian', :type => 'User', :password => "password", :email => "bill@visige.co.nz"},
			 {:name => 'Ben', :description => 'Friend of Bill and Bob', :type => 'User', :password => "password", :email => "ben@visige.co.nz"},
			 {:name => 'Bam', :description => 'Friend of Bill and Bob', :type => 'User', :password => "password", :email => "bam@visige.co.nz"},
			 {:name => 'Grace', :description => 'Database guru', :type => 'User', :password => "password", :email => "pygn@visige.co.nz"},
			 {:name => 'Harry', :description => 'Friend of Grace', :type => 'User', :password => "password", :email => "harry@visige.co.nz"},
			 {:name => 'Hector', :description => 'Another friend of Grace', :type => 'User', :password => "password", :email => "hector@visige.co.nz"},
			 {:name => 'Humphrey', :description => 'Friend of Adrian and Grace', :type => 'User', :password => "password", :email => "humphrey@visige.co.nz"},
			 {:name => 'Herman', :description => 'Friend of Harry and Bob', :type => 'User', :password => "password", :email => "herman@visige.co.nz"},
			 {:name => 'Ethan', :description => 'LoL Player', :type => 'User', :password => "password", :email => "doommaggot@visige.co.nz"},
			 {:name => 'Michael', :description => 'Handsome Bachelor', :type => 'User', :password => "password", :email => "gypsyjuggler@visige.co.nz"},
			 {:name => 'Blah', :description => 'Tester', :type => 'User', :password => "password", :email => "blah@visige.co.nz"}
			 ])

#establishing relationships
Friendship.create([ {:entity_id => User.find_by_name("Adrian").id, :friend_id => User.find_by_name("Bob").id, :accepted => true},
				    {:entity_id => User.find_by_name("Adrian").id, :friend_id => User.find_by_name("Bill").id, :accepted => true},
					{:entity_id => User.find_by_name("Bob").id, :friend_id => User.find_by_name("Ben").id, :accepted => true},
					{:entity_id => User.find_by_name("Bob").id, :friend_id => User.find_by_name("Bam").id, :accepted => true},
					{:entity_id => User.find_by_name("Bill").id, :friend_id => User.find_by_name("Ben").id, :accepted => true},
					{:entity_id => User.find_by_name("Bill").id, :friend_id => User.find_by_name("Bam").id, :accepted => true},
					{:entity_id => User.find_by_name("Grace").id, :friend_id => User.find_by_name("Harry").id, :accepted => true},
					{:entity_id => User.find_by_name("Grace").id, :friend_id => User.find_by_name("Hector").id, :accepted => true},
					{:entity_id => User.find_by_name("Adrian").id, :friend_id => User.find_by_name("Humphrey").id, :accepted => true},
					{:entity_id => User.find_by_name("Grace").id, :friend_id => User.find_by_name("Humphrey").id, :accepted => true},
					{:entity_id => User.find_by_name("Harry").id, :friend_id => User.find_by_name("Herman").id, :accepted => true},
					{:entity_id => User.find_by_name("Bob").id, :friend_id => User.find_by_name("Herman").id, :accepted => true}])

#Friendship.create(:entity_id => User.find_by_name("Blah").id, :friend_id => User.find_by_name("Adrian").id, :accepted => false)
#Friendship.create(:entity_id => User.find_by_name("Blah").id, :friend_id => User.find_by_name("Bam").id, :accepted => false)

#group with single admin, many friends
User.find_by_name("Harry").create_group("H Club", "People whose names begin with H",false)
Friendship.create([ {:entity_id => Group.find_by_name("H Club").id, :friend_id => User.find_by_name("Herman").id, :accepted => true},
					{:entity_id => Group.find_by_name("H Club").id, :friend_id => User.find_by_name("Hector").id, :accepted => true},
					{:entity_id => Group.find_by_name("H Club").id, :friend_id => User.find_by_name("Humphrey").id, :accepted => true}])

# group with many admins, no friends
User.find_by_name("Adrian").create_group("MGM", "Mega Game Mage",true)
Group.find_by_name("MGM").grant_admin(User.find_by_name("Grace").id)
Group.find_by_name("MGM").grant_admin(User.find_by_name("Michael").id)
Group.find_by_name("MGM").grant_admin(User.find_by_name("Ethan").id)